﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FirstFloor.Documents.Pdf.ColorSpaces
{
    /// <summary>
    /// Represents the CalGray color space.
    /// </summary>
    internal class CalGray
        : ColorSpace
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CalGray"/> class.
        /// </summary>
        public CalGray()
        {
            this.Name = "CalGray";
            this.DefaultColor = new double[] { 0 };

            this.WhitePoint = new ColorPoint() { X = 1, Y = 1, Z = 1 };
            this.BlackPoint = new ColorPoint() { X = 0, Y = 0, Z = 0 };
            this.Gamma = 1;
        }

        /// <summary>
        /// Specifies the tristimulus value of the diffuse white point.
        /// </summary>
        /// <value>The white point.</value>
        public ColorPoint WhitePoint { get; set; }
        /// <summary>
        /// Specifies the tristimulus value of the diffuse black point.
        /// </summary>
        /// <value>The black point.</value>
        public ColorPoint BlackPoint { get; set; }
        /// <summary>
        /// Defines the gamma for the gray component.
        /// </summary>
        /// <value>The gamma.</value>
        public double Gamma { get; set; }

        /// <summary>
        /// Converts specified value to the XYZ color space.
        /// </summary>
        /// <param name="values">The values.</param>
        /// <returns></returns>
        public override ColorPoint ToXYZ(params double[] values)
        {
            return new ColorPoint() {
                X = Math.Pow(values[0], this.Gamma) * this.WhitePoint.X,
                Y = Math.Pow(values[0], this.Gamma) * this.WhitePoint.Y,
                Z = Math.Pow(values[0], this.Gamma) * this.WhitePoint.Z
            };
        }
    }
}
